#ifndef _HXSY_H
#define _HXSY_H

#if ARDUINO < 100
#include <WProgram.h>

#else
#include <Arduino.h>
#endif





class HXSY
{
public:
    
	
	long current_leftPosition = 0;  // Global variable for storing the current encoder position
	long current_rightPosition = 0;  // Global variable for storing the current encoder position
	
	
    void HX_MP3_VOL(unsigned char vo);
	void HX_MP3_play(unsigned int vo);
    unsigned char HXGETDISTENCE(unsigned char d);
    void HXsetColor(unsigned char d,unsigned char s,long int color);
    bool  LIGHT_B_W(unsigned char aa,unsigned char bb,unsigned char cc);
	bool  LIGHT5_B_W(unsigned char aa,unsigned char bb,unsigned char cc);
    void WriteSEG(unsigned char KEY2,unsigned int SEGdat);
    void waitbutton(unsigned char KEY1,unsigned char swKEY1);
    bool buttonPressed(unsigned char KEY,unsigned char swKEY);
    void MOTOR_STOP_ONE(unsigned char aaa);
	void MOTOR_steup();
	void MOTOR_STOP();
	void MOTOR_SEND_START(unsigned char aa,int bb);
	void MOTOR4_SEND_START(int a1,int a2);
	void MOTORCD_SEND_START(int a3,int a4);
	int GETBMDJ(char sw);
	void findBMA();
	void findBMB();
	
	
	
protected:

private:
     unsigned char motorspeed[4] = {0,0,0,0};
     unsigned char SEG[4]={0,0,0,0};
     unsigned char segbuff;
     unsigned int segcnt;
	 unsigned char MOTORcorlbuff[4] = {0,0,0,0};
     unsigned char MOTORcorl[4] = {0,0,0,0};
	 unsigned int cs100Abuff[4];
	 
	 
	 
	 
	 
	 void CS100A_SEND(unsigned char AA)
	 {
		 unsigned char csbuff;
		 
		 pinMode(AA, OUTPUT);	 
		 for(char i=0;i<4;i++)
		 {
		      digitalWrite(AA, LOW);//拉低总线，请求通信
		      delayMicroseconds (100) ;
		      digitalWrite(AA, HIGH);//拉低总线，请求通信
		      csbuff = cs100Abuff[i];
		       for(char j=0;j<8;j++)
		       {
		           if(csbuff & 0x80)
		           {
		               digitalWrite(AA, HIGH); 
		               delayMicroseconds (100) ;//延时100us
		           }
		           else
		           {
		               digitalWrite(AA, LOW); 
		               delayMicroseconds (100) ;//延时100us
		           }
		           csbuff = csbuff<<1; 
		       }     
		 }
		  digitalWrite(AA, HIGH);
		 
	 }
	 char MOTOR_send()
	 {
			unsigned char MOTORbuff;
			unsigned char cnt = 0;
			  pinMode(2, OUTPUT);
			
			  
			  for(char i=0;i<4;i++)
			  {
				  MOTORbuff = MOTORcorl[i];
			       digitalWrite(2, LOW);//拉低总线，请求通信
			       delay(1);
			       digitalWrite(2, HIGH);//拉低总线，请求通信
			       
			        for(char j=0;j<8;j++)
			        {
			            if(MOTORbuff & 0x80)
			            {
			                digitalWrite(2, HIGH); 
			                delayMicroseconds (100) ;//延时100us
			            }
			            else
			            {
			                digitalWrite(2, LOW); 
			                delayMicroseconds (100) ;//延时100us
			            }
			            MOTORbuff = MOTORbuff<<1; 
			        }     
			  }
			  pinMode(2, OUTPUT);
			  digitalWrite(2, HIGH);
			  delay(8);

			  
			  		 
	 }
};

#endif // _HXSY_H
